/* ==========================================================
 * bootstrap-affix.js v2.3.1
 * http://twitter.github.com/bootstrap/javascript.html#affix
 * ==========================================================
 * Copyright 2012 Twitter, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ========================================================== */


!function ($) {

  "use strict"; // jshint ;_;


 /* AFFIX CLASS DEFINITION
  * ====================== */

  var Affix = function (element, options) {
    this.options = $.extend({}, $.fn.affix.defaults, options);
    this.$window = $(window)
      .on('scroll.affix.data-api', $.proxy(this.checkPosition, this))
      .on('click.affix.data-api',  $.proxy(function () { setTimeout($.proxy(this.checkPosition, this), 1) }, this));
    this.$element = $(element);
    this.checkPosition();
  };

  Affix.prototype.checkPosition = function () {
    if (!this.$element.is(':visible')) return;

    var scrollHeight = $(document).height()
      , scrollTop = this.$window.scrollTop()
      , position = this.$element.offset()
      , offset = this.options.offset
      , offsetBottom = offset.bottom
      , offsetTop = offset.top
      , reset = 'affix affix-top affix-bottom'
      , affix;

    if (typeof offset != 'object') offsetBottom = offsetTop = offset;
    if (typeof offsetTop == 'function') offsetTop = offset.top();
    if (typeof offsetBottom == 'function') offsetBottom = offset.bottom();

    affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ?
      false    : offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ?
      'bottom' : offsetTop != null && scrollTop <= offsetTop ?
      'top'    : false;

    if (this.affixed === affix) return;

    this.affixed = affix;
    this.unpin = affix == 'bottom' ? position.top - scrollTop : null;

    this.$element.removeClass(reset).addClass('affix' + (affix ? '-' + affix : ''));
  };


 /* AFFIX PLUGIN DEFINITION
  * ======================= */

  var old = $.fn.affix;

  $.fn.affix = function (option) {
    return this.each(function () {
      var $this = $(this)
        , data = $this.data('affix')
        , options = typeof option == 'object' && option;
      if (!data) $this.data('affix', (data = new Affix(this, options)));
      if (typeof option == 'string') data[option]();
    });
  };

  $.fn.affix.Constructor = Affix;

  $.fn.affix.defaults = {
    offset: 0
  };


 /* AFFIX NO CONFLICT
  * ================= */

  $.fn.affix.noConflict = function () {
    $.fn.affix = old;
    return this;
  };


 /* AFFIX DATA-API
  * ============== */

  $(window).on('load', function () {
    $('[data-spy="affix"]').each(function () {
      var $spy = $(this)
        , data = $spy.data();

      data.offset = data.offset || {};

      data.offsetBottom && (data.offset.bottom = data.offsetBottom);
      data.offsetTop && (data.offset.top = data.offsetTop);

      $spy.affix(data);
    });
  });


}(window.jQuery);


// JavaScript Document
$(document).ready(function() {
	$.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };
    
 // Enable placholder attribute for all browsers

	$(function() {
		 var $win = $(window);
	     var $nav = $('.subnav');
	     var navTop = $nav.length && $nav.offset().top-50;
	     var isFixed = 0;

	    processScroll();
	    $nav.on('click', function () {
	      if (!isFixed) setTimeout(function () {  $win.scrollTop($win.scrollTop() - 47); }, 10);
	    });
	    $win.on('scroll', processScroll);
	    function processScroll() {
	      var scrollTop = $win.scrollTop();
	      if (scrollTop >= navTop && !isFixed) {
	        isFixed = 1;
	        $nav.addClass('subnav-fixed');
	      } else if (scrollTop <= navTop && isFixed) {
	        isFixed = 0;
	        $nav.removeClass('subnav-fixed');
	      }
	    }
	});
	
	$(function() {
		var scrtime;
		$("#con").hover(function() {
			clearInterval(scrtime);
		}, function() {

			scrtime = setInterval(function() {
				var $ul = $("#con ul");
				var liHeight = $ul.find("li:last").height();
				$ul.animate({
					marginTop : liHeight + 20 + "px"
				}, 1000, function() {

					$ul.find("li:last").prependTo($ul);
					$ul.find("li:first").hide();
					$ul.css({
						marginTop : 0
					});
					$ul.find("li:first").fadeIn(1000);
				});
			}, 5000);

		}).trigger("mouseleave");
	});


	if (!+'\v1' && !('maxHeight' in document.body.style)) {
		window['FXL_IE6'] = 1;
	} else {
		window['FXL_IE6'] = 0;
	}

	// 回到顶部按钮
	$("#BackToTop").hide();
	$(function() {
		$(window).scroll(function() {
			if ($(this).scrollTop() > 100) {
				$('#BackToTop').fadeIn();
			} else {
				$('#BackToTop').fadeOut();
			}
		});
		$('#BackToTop').click(function() {
			//$('body,html').animate({scrollTop:0},800);
			$.scrollTo(0,500); 
		});	
	});
	
    $.oPopover('user_profile',{
		autoDirection : true,
    	remote : url_userprofile,
		elem_mark : 'a[data-user-profile="1"]',
		data_id_mark : 'data-user-id',
		tpl_mark : 'user_profile_tpl'
	});
    
});